using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace Ares
{
    class TorManager
    {
        private string FTorPath;
        private string FConfigFile;
        private Process FTor;
        private bool FShowTorWindow = false;

        public bool ShowTorWindow
        {
            get
            {
                return this.FShowTorWindow;
            }

            set
            {
                if (this.FTor != null)
                    throw new Exception("Tor already started");
                this.FShowTorWindow = value;
            }
        }
            
        public TorManager(string TorPath,string ConfigFile)
        {
            this.FTorPath = TorPath;
            this.FConfigFile = ConfigFile;
        }

        public void Start()
        {
            if (this.FTor != null)
                throw new Exception("Tor already started");

            this.FTor = new Process();
            this.FTor.StartInfo.FileName = this.FTorPath;
            this.FTor.StartInfo.Arguments = "-f \"" + this.FConfigFile + "\"";            
            this.FTor.StartInfo.UseShellExecute = false;
            this.FTor.StartInfo.CreateNoWindow = !this.FShowTorWindow;
            this.FTor.Start();
        }

        public void Stop()
        {
            if (this.FTor == null)
                throw new Exception("Tor isn't working");
            this.FTor.Kill();
        }
    }
}
